package com.bsj.power.job.web.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.bsj.power.common.config.global.JsonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yinhao
 * @version 1.0
 * @description
 * @date 2024/4/17
 */
@RestController
@RequestMapping("/test/")
public class TestController {

    @RequestMapping("doLogin")
    public JsonResult doLogin(String username, String password) {
        // 此处仅作模拟示例，真实项目需要从数据库中查询数据进行比对
        if("zhang".equals(username) && "123456".equals(password)) {
            StpUtil.login(10001);
            return JsonResult.success("登录成功");
        }
        return JsonResult.fail("登录失败");
    }

    @RequestMapping("isLogin")
//    @SaCheckPermission("user")
    public JsonResult isLogin() {
        return JsonResult.success("当前会话是否登录：" + StpUtil.isLogin());
    }

    @RequestMapping("isLoginType")
    public JsonResult isLoginType() {
        StpUtil.logout(10001);
        return JsonResult.success("当前会话是否登录：" + StpUtil.isLogin());
    }
}
